/*     */ package com.zimbra.cs.dav.resource;
/*     */ 
/*     */ import com.zimbra.client.ZFolder;
/*     */ import com.zimbra.client.ZFolder.View;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMailbox.Options;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.dav.DavContext;
/*     */ import com.zimbra.cs.dav.DavElements;
/*     */ import com.zimbra.cs.dav.DavException;
/*     */ import com.zimbra.cs.dav.property.Acl;
/*     */ import com.zimbra.cs.dav.property.ResourceProperty;
/*     */ import com.zimbra.cs.mailbox.ACL;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Mountpoint;
/*     */ import com.zimbra.cs.mailbox.calendar.cache.CtagInfo;
/*     */ import com.zimbra.cs.service.AuthProvider;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import java.io.IOException;
/*     */ import java.util.Collections;
/*     */ import org.dom4j.Element;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class RemoteCollection
/*     */   extends Collection
/*     */ {
/*     */   protected String mRemoteOwnerId;
/*     */   protected int mRemoteId;
/*     */   protected String mCtag;
/*  51 */   protected short mRights = 0;
/*     */   
/*     */   public RemoteCollection(DavContext ctxt, Mountpoint mp) throws DavException, ServiceException {
/*  54 */     super(ctxt, mp);
/*  55 */     this.mRemoteOwnerId = mp.getOwnerId();
/*  56 */     this.mRemoteId = mp.getRemoteId();
/*  57 */     addResourceType(DavElements.E_MOUNTPOINT);
/*  58 */     getMountpointTarget(ctxt);
/*  59 */     this.mMailboxId = 0;
/*  60 */     Account target = Provisioning.getInstance().get(Key.AccountBy.id, this.mRemoteOwnerId);
/*  61 */     if ((target != null) && (Provisioning.onLocalServer(target)))
/*  62 */       this.mMailboxId = MailboxManager.getInstance().getMailboxByAccount(target).getId();
/*     */   }
/*     */   
/*     */   public RemoteCollection(DavContext ctxt, String path, Account user) throws DavException, ServiceException {
/*  66 */     super(path, user.getName());
/*  67 */     ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
/*  68 */     ZMailbox mbox = getRemoteMailbox(zat, user.getId());
/*  69 */     ZFolder folder = mbox.getFolderByPath(path);
/*  70 */     if (folder == null)
/*  71 */       throw MailServiceException.NO_SUCH_FOLDER(path);
/*  72 */     this.mOwnerId = user.getId();
/*  73 */     this.mId = new ItemId(folder.getId(), this.mOwnerId).getId();
/*  74 */     this.mPath = path;
/*  75 */     this.mSubject = folder.getName();
/*  76 */     this.type = MailItem.Type.FOLDER;
/*  77 */     ZFolder.View zview = folder.getDefaultView();
/*  78 */     if (zview != null) {
/*  79 */       this.view = MailItem.Type.of(zview.name());
/*     */     }
/*     */   }
/*     */   
/*     */   public void delete(DavContext ctxt) throws DavException {
/*  84 */     throw new DavException("cannot delete this resource", 403, null);
/*     */   }
/*     */   
/*     */   public java.util.Collection<DavResource> getChildren(DavContext ctxt) throws DavException
/*     */   {
/*  89 */     return Collections.emptyList();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*  94 */   public DavResource createItem(DavContext ctxt, String name) throws DavException, IOException { throw new DavException("request should be proxied", 500); }
/*     */   
/*     */   static ZMailbox getRemoteMailbox(ZAuthToken zat, String ownerId) throws ServiceException {
/*  97 */     Account target = Provisioning.getInstance().get(Key.AccountBy.id, ownerId);
/*  98 */     if (target == null)
/*  99 */       return null;
/* 100 */     ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
/* 101 */     zoptions.setNoSession(true);
/* 102 */     zoptions.setTargetAccount(ownerId);
/* 103 */     zoptions.setTargetAccountBy(Key.AccountBy.id);
/* 104 */     return ZMailbox.getMailbox(zoptions);
/*     */   }
/*     */   
/* 107 */   protected void getMountpointTarget(DavContext ctxt) throws ServiceException { ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
/* 108 */     ZMailbox zmbx = getRemoteMailbox(zat, this.mRemoteOwnerId);
/* 109 */     if (zmbx == null)
/* 110 */       return;
/* 111 */     ZFolder folder = zmbx.getFolder(new ItemId(this.mRemoteOwnerId, this.mRemoteId).toString(this.mOwnerId));
/* 112 */     if (folder == null)
/* 113 */       return;
/* 114 */     this.mCtag = CtagInfo.makeCtag(folder);
/* 115 */     setProperty(DavElements.E_GETCTAG, this.mCtag);
/* 116 */     this.mRights = ACL.stringToRights(folder.getEffectivePerms());
/* 117 */     addProperty(Acl.getCurrentUserPrivilegeSet(this.mRights));
/* 118 */     addProperty(Acl.getMountpointTargetPrivilegeSet(this.mRights));
/* 119 */     String targetUrl = UrlNamespace.getResourceUrl(Provisioning.getInstance().get(Key.AccountBy.id, this.mRemoteOwnerId), folder.getPath() + "/");
/* 120 */     ResourceProperty mp = new ResourceProperty(DavElements.E_MOUNTPOINT_TARGET_URL);
/* 121 */     mp.addChild(DavElements.E_HREF).setText(targetUrl);
/* 122 */     addProperty(mp);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/resource/RemoteCollection.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */